package com.b2c.ftysys.sevice.impl;

import java.util.List;

import org.directwebremoting.annotations.RemoteProxy;
import org.directwebremoting.create.NewCreator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.b2c.ftysys.dao.B2cFsyWsDAO;
import com.b2c.ftysys.dao.DatabaseException;
import com.b2c.ftysys.domain.B2cFsyWs;
import com.b2c.ftysys.domain.B2cFsyWsExample;
import com.b2c.ftysys.domain.B2cFsyWsExample.Criteria;
import com.b2c.ftysys.sevice.WsInfoService;

@Service(value="WsInfoService")
@RemoteProxy(creator=NewCreator.class,name="wsService")
public class WsInfoServiceImpl implements WsInfoService {
	@Autowired
	private B2cFsyWsDAO wsDao;

	public B2cFsyWsDAO getWsDao() {
		return wsDao;
	}

	public void setWsDao(B2cFsyWsDAO wsDao) {
		this.wsDao = wsDao;
	}

	public int createWs(B2cFsyWs ws) {
		B2cFsyWsExample example = new B2cFsyWsExample();
		example.createCriteria().andWsNameEqualTo(ws.getWsName());
		if (wsDao.countByExample(example) > 0)
			return 0;
		wsDao.save(ws);
		return 1;
	}

	public List<B2cFsyWs> queryAllWs() {
		try {
			return wsDao.getList("b2c_fsy_ws.abatorgenerated_selectAll");
		} catch (DatabaseException e) {
			e.printStackTrace();
			return null;
		}
	}

	public List<B2cFsyWs> queryWsListByClause(B2cFsyWs example) {
		B2cFsyWsExample clause = new B2cFsyWsExample();
		Criteria clauseO = clause.createCriteria();

		if (example == null)
			example = new B2cFsyWs();
		if (example.getWsId() != null && example.getWsId() != 0)
			clauseO.andWsIdEqualTo(example.getWsId());

		if (example.getWsName() != null
				&& example.getWsName().trim().length() > 0)
			clauseO.andWsNameEqualTo(example.getWsName());

		if (example.getWsComment() != null
				&& example.getWsComment().trim().length() > 0)
			clauseO.andWsCommentEqualTo(example.getWsComment());

		return wsDao.selectByExample(clause);
	}

	public int removeWs(int staffId) {
		return wsDao.deleteByPrimaryKey(staffId);
	}

	public int updateWs(B2cFsyWs staff) {
		return wsDao.updateByPrimaryKeySelective(staff);
	}

}
